<template>
  <div class="goodlist">
    <router-link class="goods-item" to="/home" v-for="(item) in list" :key="item.id">
      <img :src="item.img_url" alt="商品图片">
      <h1 class="title">{{item.title}}</h1>
      <div class="info">
        <p class="price">
          <span class="now">￥{{item.sell_price}}</span>
          <span class="old">￥{{item.market_price}}</span>
        </p>
        <p>
          <span>热卖中</span>
          <span>剩{{item.stock_quantity}}</span>
        </p>
      </div>
    </router-link>
  </div>
</template>

<script>
export default {
  data(){
    return{
      pageindex: 1,
      list:[]
    }
  },
  methods:{

  },
  created(){
    this.$http.get("api/getgoods?pageindex=" + this.pageindex).then(result=>{
      if(result.body.status == 0){
        this.list = result.body.message;
      }
    })
  }
};
</script>

<style scoped>
.goodlist{
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 10px 10px;
}

.goods-item{
  width: 48%;
  border: 1px solid #ccc;
  box-shadow: 0 0 8px #ccc;
  margin: 4px 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

img{
  width: 100%;
}

.title{
  font-size: 14px;
}

.old{
  text-decoration: line-through;
  font-size: 12px;
}

.now{
  color: red;
  font-weight: bold;
}
</style>